<?php
/**
 * JE Career package
 * @author J-Extension <contact@jextn.com>
 * @link http://www.jextn.com
 * @copyright (C) 2012 - 2013 J-Extension
 * @license GNU/GPL, see LICENSE.php for full license.
**/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');

class hostingrajacareerControllerCareer extends JController
{

	function __construct( $config = array() )
	{
		parent::__construct( $config );
	}

	function display()
	{
		JRequest::setVar( 'view', 'career');
		parent::display();
	}

	function edit()
	{
		JRequest::setVar( 'view', 'career');
		JRequest::setVar( 'layout', 'default_form'  );
		JRequest::setVar('hidemainmenu', 1);
		parent::display();
	}

	function save()
	{
		$enablecaptcha 	= false;
		$model 			= $this->getModel('career');
		$settings	   	= $model->getGlobalsettings();
		$itmid = JRequest::getVar('Itemid');

		// Get session
		$session 	   = & JFactory::getSession();
		$catid	 	   = &JRequest::getInt('catid');
		$post		   = &JRequest::get('post');

		if ($settings->show_captcha == '1' ){
			$enablecaptcha 		= true;
		}

		// check captch variables..
		if (AutartiCaptchaHelper::checkCaptcha( $enablecaptcha )) {
			if ($cid = $model->store()){
				$session->clear('formvalues');
				if($cid=='format'){
					// get the raw value of myField
					$formValue 	= JRequest::get('POST');
					// add the value to the session namespace myForm
					$session->set('formvalues', $formValue);
					$formats	=$settings->file_format;
					$formats	=str_ireplace(",",", ",$formats);
					if($settings->file_format==''){
						$formats='doc, pdf, txt, pptx';
					}
					$session->set('error', JText::_( 'JE_FILE_ERROR_FORMAT' ).' '.$formats);
					$link 		= JRoute::_( 'index.php?option=com_hostingrajacareer&view=career&task=edit&cid='.$post['co_id'].'&Itemid='.$itmid );

				}
				else if($cid=='size'){
					// get the raw value of myField
					$formValue 	= JRequest::get('POST');
					// add the value to the session namespace myForm
					$session->set('formvalues', $formValue);
					$session->set('error', JText::_( 'JE_FILE_ERROR_SIZE' ));
					$link 		= JRoute::_( 'index.php?option=com_hostingrajacareer&view=career&task=edit&cid='.$post['co_id'].'&Itemid='.$itmid );

				}
				else if($cid=='notupload'){
					// get the raw value of myField
					$formValue 	= JRequest::get('POST');
					// add the value to the session namespace myForm
					$session->set('formvalues', $formValue);
					$session->set('error', JText::_( 'JE_FILE_ERROR_NOT_UPLOAD' ));
					$link 		= JRoute::_( 'index.php?option=com_hostingrajacareer&view=career&task=edit&cid='.$post['co_id'].'&Itemid='.$itmid );
				}
				else{
					$itmid 		= JRequest::getVar('Itemid');

					$link 		= 'index.php?option=com_hostingrajacareer&view=career&layout=default_success';
				}
			}
		}
		else{
			// get the raw value of myField
			$formValue 			= JRequest::get('POST');
			// add the value to the session namespace myForm
			$session->set('formvalues', $formValue);
			$session->set('error', 'Captcha doesn\'t match');

			$link 				= JRoute::_( 'index.php?option=com_hostingrajacareer&view=career&task=edit&cid='.$post['co_id'].'&Itemid='.$itmid );
		}

		$this->setRedirect($link);
	}

}
?>